﻿using System.Collections.ObjectModel;

namespace AB.ServiceDirectory
{
    public static class StringTools
    {
        /// <summary>
        /// Substrings the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="length">The length.</param>
        /// <param name="withDot">if set to <c>true</c> [with dot].</param>
        /// <returns></returns>
        public static string Substring(object value, int startIndex, int length, bool withDot)
        {
            if (value == null)
            {
                return string.Empty;
            }

            if (value.ToString().Length <= length)
            {
                return value.ToString();
            }

            var tempStr = value.ToString().Substring(startIndex, length);
            if (withDot)
            {
                var lastIndex = tempStr.LastIndexOf(' ');
                tempStr = tempStr.Substring(startIndex, lastIndex) + "...";
            }
            return tempStr;
        }

        /// <summary>
        /// Gets the letter group.
        /// </summary>
        /// <param name="letterGroup">The letter group.</param>
        /// <returns></returns>
        public static Collection<string> GetLetterGroup(string letterGroup)
        {
            Collection<string> letters = null;
            switch (letterGroup)
            {
                case "09":
                    letters = new Collection<string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
                    break;

                case "ae":
                    letters = new Collection<string> { "a", "b", "c", "d", "e" };
                    break;

                case "fj":
                    letters = new Collection<string> { "f", "g", "h", "i", "j" };
                    break;

                case "kn":
                    letters = new Collection<string> { "k", "l", "m", "n" };
                    break;

                case "or":
                    letters = new Collection<string> { "o", "p", "q", "r" };
                    break;

                case "sv":
                    letters = new Collection<string> { "s", "t", "u", "v" };
                    break;

                case "wz":
                    letters = new Collection<string> { "w", "x", "y", "z" };
                    break;
            }

            return letters;
        }
    }
}